
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.ArrayList,
                 com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.users.Functionality,
				 com.scalar.chiptrack.sales.ContactPerson" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<%
    String  vendorMailAttachmentType = (String) request.getAttribute("vendorMailAttachmentType");
    String  disableStr = "";
    if( vendorMailAttachmentType != null )
    {
        disableStr="disabled=true";
    }
    if ( vendorMailAttachmentType == null )
    {
%>
    <chiptrack:checkLogon sourcePage="/sendMail.do"/>
<%  } %>

<html:html locale="true">

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel=stylesheet>
<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor="#FDF5E6" leftMargin=0 topMargin=0 marginheight="0" marginwidth="0" >

<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js">
</script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js">
</script>

<script language='javascript'>

function save()
{
    var count = document.sendPSMailForm.count.value;

	var emailid = '';
    for( i = 0; i < count; i++)
    {
        var value1 = eval("document.sendPSMailForm.selectedValue"+i).checked;
        if( value1 == true)
        {
            if(emailid != '')
            {
                emailValue = eval("document.sendPSMailForm.selectedValue"+i).value;
                if( emailValue != '')
                {
                    emailid =  emailid +" , "+ emailValue;
                }
                else
                {
                    emailid =  emailid;
                }
            }
            else
            {
                emailid =  eval("document.sendPSMailForm.selectedValue"+i).value;
            }
        }
    }

    for( var x = 0 ; x < window.opener.document.sendMailForm.elements.length ; x++ )
    {
       var tmpElement = window.opener.document.sendMailForm.elements[x];
       if( tmpElement.type == "text")
       {
            if( tmpElement.name == "toUsers" )
            {
                if( typeof tmpElement.length == 'undefined' )
                {
                    tmpElement.value =  emailid;
                    break;
                }
                else
                {
                    tmpElement[0].value = emailid;
                    break;
                }
             }
       }
    }
    document.sendPSMailForm.action.value  = "displayPrvMailIds";
    document.sendPSMailForm.submit();
    window.close();
}

function reset()
{
    document.sendPSMailForm.reset();
}

function closeWindow(form) {
   // window.opener.document.sendRmaMailForm.submit();
 	window.close();
}

</script>


<!-- from here your body starts -->

<html:form name="sendPSMailForm" type="com.scalar.chiptrack.operations.packingslip.forms.SendMailForm" action="/sendMail.do">
<table border="0" width="100%" align="center">
	<tr><td bgcolor="#993333" align="center" class="NArialW"><font color='#FFFFFF'>Contact Person Details</font></td></tr>
</table>
<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20>
<table border="0" width="90%" align="right">
	<tr>
		<td width="100%">
			<table border="0" width="100%" cellspacing='10' cellpadding='2' align='left'>
				<tr>
					<td align=right>
						 <a href="javascript:window.close();" title='Click here to close this window' onMouseOver="window.status='Click here to close this window';return true"><font class='NArialL'><b>[Close this window]</b></font></a>
					</td>
				</tr>
				<tr><td><chiptrack:errors styleClass='NArialL' /></td></tr>
				<tr><td><chiptrack:info styleClass='NArialL' /></td></tr>
				<tr><td align="left" class='NArialL'><FONT id="errors" styleClass="NArialL" color='FF0000'></font></td></tr>
			</table>
		</td>
	</tr>
	<tr>
		<td>
			<!-- DISPLAY ALL USERS STARTS HERE -->
			<%
               String recipientType = (String)session.getAttribute("recipientType");
               ArrayList contactPersons = null;

               if("customer".equals(recipientType) )
               {
			         contactPersons = (ArrayList) request.getAttribute("PSContactPersons");
               }
               else
               {
                     contactPersons = (ArrayList) request.getAttribute("PSVendorContactPersons");
               }
               String types[] = ( String[] ) session.getAttribute("types");
               String vtypes[] = ( String[] ) session.getAttribute("vtypes");
               //System.out.println("<<< Size " + session.getAttribute("RmaShowAgain") );
				if( contactPersons != null && contactPersons.size() != 0 ) { %>

			   <table border="0" width="70%" align="center">
				<tr>
					<td width="5%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Select</font></font></td>
					<td width="15%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Contact Person</font></font></td>
					<td width="15%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Email</font></font></td>
                    <td width="15%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Type</font></font></td>
				</tr>
				<%   int Cnt = 0 ; %>
                <%
                if("customer".equals(recipientType) )
                {
                %>
				<logic:iterate id="ContactPerson" name="PSContactPersons" type="com.scalar.chiptrack.sales.ContactPerson">
                    <% int bgcount = 0;%>
                    <% bgcount = bgcount + 1; %>
                    <tr>
                        <td nowrap width="5%" align="left" <%if(bgcount%2==0){%> bgcolor='#DEE1E2' <% } else {%> bgcolor='#FFFFEE' <%}%>><font class="NArialL">
                            <logic:equal name="ContactPerson" property="isChecked" value="true">
                                <input type="checkbox" name="selectedValue<%=Cnt%>" value='<%=ContactPerson.getEmail()%>' CHECKED <%=disableStr%>>
                            </logic:equal>
                            <logic:equal name="ContactPerson" property="isChecked" value="false">
                                <input type="checkbox" name="selectedValue<%=Cnt%>" value='<%=ContactPerson.getEmail()%>' <%=disableStr%>>
                            </logic:equal>
                            </font>
                        </td>
                        <td nowrap width="15%" align="left" <%if(bgcount%2==0){%> bgcolor='#DEE1E2' <% } else {%> bgcolor='#FFFFEE' <%}%>><font class="NArialL">
                            <bean:write name="ContactPerson" property="contactPerson" /></font>
                        </td>
                        <td nowrap width="15%" align="left" <%if(bgcount%2==0){%> bgcolor='#DEE1E2' <% } else {%> bgcolor='#FFFFEE' <%}%>><font class="NArialL">
                            <bean:write name="ContactPerson" property="email" /></font>
                        </td>
                        <td nowrap width="15%" align="left" <%if(bgcount%2==0){%> bgcolor='#DEE1E2' <% } else {%> bgcolor='#FFFFEE' <%}%>><font class="NArialL">
                            <% out.println(types[Cnt]); %></font>
                        </td>
                    </tr>
				<% Cnt = Cnt + 1; %>
				</logic:iterate>
                <%
                 }
                 else
                 {
                %>
                <logic:iterate id="ContactPerson" name="PSVendorContactPersons" type="com.scalar.chiptrack.sales.ContactPerson">
                    <%int bgcount = 0;%>
                    <% bgcount = bgcount + 1; %>
                    <tr>
                        <td nowrap width="5%" align="left" <%if(bgcount%2==0){%> bgcolor='#DEE1E2' <% } else {%> bgcolor='#FFFFEE' <%}%>><font class="NArialL">
                            <logic:equal name="ContactPerson" property="isChecked" value="true">
                                <input type="checkbox" name="selectedValue<%=Cnt%>" value='<%=ContactPerson.getEmail()%>' CHECKED <%=disableStr%>>
                            </logic:equal>
                            <logic:equal name="ContactPerson" property="isChecked" value="false">
                                <input type="checkbox" name="selectedValue<%=Cnt%>" value='<%=ContactPerson.getEmail()%>' <%=disableStr%>>
                            </logic:equal>
                            </font>
                        </td>
                        <td nowrap width="15%" align="left" <%if(bgcount%2==0){%> bgcolor='#DEE1E2' <% } else {%> bgcolor='#FFFFEE' <%}%>><font class="NArialL">
                            <bean:write name="ContactPerson" property="contactPerson" /></font>
                        </td>
                        <td nowrap width="15%" align="left" <%if(bgcount%2==0){%> bgcolor='#DEE1E2' <% } else {%> bgcolor='#FFFFEE' <%}%>><font class="NArialL">
                            <bean:write name="ContactPerson" property="email" /></font>
                        </td>
                        <td nowrap width="15%" align="left" <%if(bgcount%2==0){%> bgcolor='#DEE1E2' <% } else {%> bgcolor='#FFFFEE' <%}%>><font class="NArialL">
                            <% out.println(vtypes[Cnt]); %></font>
                        </td>
                    </tr>
                    <% Cnt = Cnt + 1; %>
				</logic:iterate>
                <%}%>
				<input type="hidden" name="count" value ='<%=Cnt%>' >
				<tr><td class="NArialL" colspan=5><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=50></td></tr>
				<tr>
                    <td colspan=4 align=center>
                        <% if( vendorMailAttachmentType == null ) { %>
                        <a href="javascript:save()"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/submit.gif" width="53" height="17"></a>
                        <a href="javascript:reset()"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17"></a>
                        <% } %>
				    </td>
                </tr>
			</table>
				<% }
				else
				{ %>
                    <table border="0" width="70%" align="center">
                        <tr>
                            <td width="5%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Select</font></font></td>
                            <td width="15%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Contact Person</font></font></td>
                            <td width="15%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Email</font></font></td>
                            <td width="15%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Type</font></font></td>
                        </tr>
                        <tr><td colspan="3" align="center" bgcolor="#FFFFEE"><font class="NArialL"><< Records not found >></td></tr>
                    </table>
				<%
				}
				%>
			<!-- DISPLAY ALL USERS ENDS HERE -->
		</td>
	</tr>
</table>
<input type="hidden" name="customerShippingId" value ='<%=request.getParameter("customerShippingId")%>' >
<input type="hidden" name="action" value="">
</html:form>

</body>

</html:html>